package tech.xiaozai.rbac.security;

import cn.hutool.crypto.digest.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-09-23 10:57
 */
public class MyMD5PasswordEncoder implements PasswordEncoder {


//    public static void main(String[] args) {
//        MyMD5PasswordEncoder encoder = new MyMD5PasswordEncoder();
//        System.out.println("123456的密文:"+encoder.encode("123456"));
//        System.out.println("admin的密文:"+encoder.encode("admin"));
//
//    }

    private MD5 md5 = MD5.create();
    @Override
    public String encode(CharSequence rawPassword) {
        return md5.digestHex(rawPassword.toString());
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(encode(rawPassword));
    }
}
